package oop.core.skill;

import oop.core.Updateable;
import oop.core.entity.Entity;
import oop.core.view.Renderable;

/**
 * Object to encapsulate a physical instance of the Skill
 * @author DangMH
 *
 */
public class SkillObject implements Renderable, Updateable, Cloneable{
	private String imageID;
	private float effect;
	private long delay;
	private boolean isActive;
	
	public SkillObject(String imageID, float effect, long lifeTime, long numHits){
		this.imageID = imageID;
		this.effect = effect;
		this.delay = lifeTime / numHits;
		this.isActive = true;
	}
	
	public SkillObject(ActiveSkill s){
		this.imageID = s.getImage();
		this.effect = s.getEffect();
		this.delay = s.getLifeTime() / s.getHitCount();
		this.isActive = true;
	}
	
	public SkillObject(ActiveSkill s, float effect){
		this.imageID = s.getImage();
		this.effect = effect;
		this.delay = s.getLifeTime() / s.getHitCount();
		this.isActive = true;
	}

	/**
	 * Calls entity e to affect the skill effect on itself.
	 * @param e
	 * @return
	 */
	public boolean doEffect(Entity e){
		if(!isActive)
			return false;
		e.takeDamage((int)effect);
		isActive = false;
		return true;
	}
	
	/**
	 * Interface implementation to schedule delays
	 */
	public void update(){
		isActive = true;
	}

	public SkillObject clone(){
		try{
		      SkillObject cloned = (SkillObject)super.clone();
		      return cloned;
	    }catch(CloneNotSupportedException e){
		      System.out.println(e);
		      return null;
	    }
	}

	public String getImageID() {
		return imageID;
	}

	public void setImageID(String imageID) {
		this.imageID = imageID;
	}

	public float getEffect() {
		return effect;
	}

	public void setEffect(float effect) {
		this.effect = effect;
	}

	public long getDelay() {
		return delay;
	}

	public void setDelay(long delay) {
		this.delay = delay;
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}
}
